import logging
import time
from appium.webdriver.common.mobileby import MobileBy
from base.base_page import BasePage


class EditMemberPage(BasePage):
    _name_locator = (MobileBy.XPATH, "//*[contains(@text,'姓名')]/../android.widget.EditText")
    _phone_locator = (MobileBy.XPATH, "//*[contains(@text,'手机')]/..//android.widget.EditText")
    _save_locator = (MobileBy.XPATH, "//*[@text='保存']")

    _delete_button_locator = (MobileBy.XPATH, "//*[@text='删除成员']")
    _alert_confirm_locator = (MobileBy.XPATH, "//*[@text='确定']")

    def add_member(self, name, phone):
        logging.info("调用add_member方法")
        self.find_and_input(name,self._name_locator)
        self.find_and_input(phone, self._phone_locator)
        self.find_and_click(self._save_locator)

        from pages.add_member_page import AddMemberPage
        return AddMemberPage(self.driver)

    def delete_member(self):
        logging.info("调用delete_member方法")
        self.find_and_click(self._delete_button_locator)
        self.find_and_click(self._alert_confirm_locator)
        time.sleep(2)
        self.back()
        from pages.contacts_page import ContactsPage
        return ContactsPage(self.driver)
